package com.winhxd.b2c.product.controller;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramAddCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramAddDetailCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramCondition;
import com.winhxd.b2c.common.domain.product.model.ProductPriceProgram;
import com.winhxd.b2c.common.domain.product.vo.ProductPriceProgramWithSpuVO;
import com.winhxd.b2c.common.feign.product.ProductPriceProgramServiceClient;
import com.winhxd.b2c.product.service.ProductPriceProgramService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ProductPriceProgramController
 * @Description 商品价格方案
 * @Author luosixiang
 * @Date 2019/1/9 15:01
 * @Version 1.0
 */

@Api(value = "商品价格方案", tags = "product PriceProgram")
@RestController
public class ProductPriceProgramController implements ProductPriceProgramServiceClient {

    @Autowired
    private ProductPriceProgramService productPriceProgramService;

    @Override
    public ResponseResult<List<ProductPriceProgram>> findAllProductPriceProgram() {
        ResponseResult<List<ProductPriceProgram>> result = new ResponseResult<>();
        result.setData(productPriceProgramService.findAllProductPriceProgram());
        return result;
    }

    @Override
    public ResponseResult<List<ProductPriceProgram>> findProductPriceProgramByModel(@RequestBody ProductPriceProgramCondition condition) {
        ResponseResult<List<ProductPriceProgram>> result = new ResponseResult<>();
        result.setData(productPriceProgramService.findProductPriceProgramByModel(condition));
        return result;
    }

    @ApiOperation(value = "查询价格方案详情")
    @Override
    public ResponseResult<ProductPriceProgramWithSpuVO> findProductPriceProgramDetail(@RequestBody ProductPriceProgramAddDetailCondition condition) {
        ResponseResult<ProductPriceProgramWithSpuVO> result = new ResponseResult<>();
        result.setData(productPriceProgramService.findProductPriceProgramDetail(condition));
        return result;
    }

    @ApiOperation(value = "删除价格方案")
    @Override
    public ResponseResult<Integer> deleteProductPriceProgram(@RequestBody ProductPriceProgramCondition condition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        result.setData(productPriceProgramService.deleteProductPriceProgram(condition.getId()));
        return result;
    }

    @ApiOperation(value = "新增价格方案")
    @Override
    public ResponseResult<Boolean> addProductPriceProgram(@RequestBody ProductPriceProgramAddCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        productPriceProgramService.addProductPriceProgram(condition);
        result.setData(true);
        result.setCode(BusinessCode.CODE_OK);
        return result;
    }

    @ApiOperation(value = "修改价格方案")
    @Override
    public ResponseResult<Boolean> modifyProductPriceProgram(@RequestBody ProductPriceProgramAddCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        productPriceProgramService.modifyProductPriceProgram(condition);
        result.setData(true);
        result.setCode(BusinessCode.CODE_OK);
        return result;
    }
    @ApiOperation(value = "通过model分页查询价格方案")
    @Override
    public ResponseResult<PagedList<ProductPriceProgram>> findProductPriceProgramPageByModel(@RequestBody ProductPriceProgramCondition productPriceProgram) {
        ResponseResult<PagedList<ProductPriceProgram>> result = new ResponseResult<>();
        result.setData(productPriceProgramService.findProductPriceProgramPageByModel(productPriceProgram));
        return result;
    }

    @ApiOperation(value = "通过model分页查询价格方案列表(不带分页)")
    @Override
    public ResponseResult<List<ProductPriceProgram>> findProductPriceProgramListByModel(@RequestBody ProductPriceProgramCondition condition) {
        ResponseResult<List<ProductPriceProgram>> result = new ResponseResult<>();
        result.setData(productPriceProgramService.findProductPriceProgramListByModel(condition));
        return result;
    }

    @Override
    public ResponseResult<Boolean> checkPriceProgramName(@RequestBody ProductPriceProgramCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        result.setData(productPriceProgramService.checkPriceProgramName(condition.getName()));
        return result;
    }
}
